﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Mobile.ContainerModel;
using Configuration;

namespace QuickStart
{
	public static class ApplicationRoot
	{
		/// <summary>
		/// Exposes the root application container where global 
		/// services are registered.
		/// </summary>
		/// <devdoc>
		/// The internal setter allows a test project to change 
		/// the container with a test one (need to enable 
		/// InternalsVisibleToAttribute at the assembly level).
		/// </devdoc>
		public static Container Container { get; internal set; }

		/// <summary>
		/// Initializes the root container.
		/// </summary>
		public static void Initialize()
		{
			var container = new Container();

			container.Register<ITaskService>(c => new TaskService(c));

			container.Register(
				c => new MainPresenter(
					c.Resolve<MainForm>(), 
					c.Resolve<ITaskService>()));

			container
				.Register(c => new MainForm())
				.InitializedBy((c, v) => v.Presenter = c.Resolve<MainPresenter>());

			Container = container;

			new ConfigurationModule().Configure(container);
		}
	}
}
